function Change(str){
	//alert(str);
	document.getElementsByClassName("txt")[0].value=str;
	document.getElementById("div1").style.display="none";
}

onload = function(){
//--------top层账户与导航的下拉--------
	var myCount = document.getElementById("myCount");
	var degimg_0 = document.getElementById("degimg_0");
	var myCountul_0 = document.getElementById("myCountul_0");

	var netNav = document.getElementById("netNav");
	var degimg_1 = document.getElementById("degimg_1");
	var netNavul_0 = document.getElementById("netNavul_0");

	myCount.onmouseover = function(){
		degimg_0.style.transform = "rotate(180deg)";
		myCountul_0.style.display = "block";
		myCountul_0.style.border = "1px solid #ccc";
		myCountul_0.style.borderTop = "none";
	}
	myCount.onmouseout = function(){
		degimg_0.style.transform = "";
		myCountul_0.style.display = "none";
	}

	netNav.onmouseover = function(){
		degimg_1.style.transform = "rotate(180deg)";
		netNavul_0.style.display = "block";
		netNavul_0.style.border = "1px solid #ccc";
		netNavul_0.style.borderTop = "none";
	}
	netNav.onmouseout = function(){
		degimg_1.style.transform = "";
		netNavul_0.style.display = "none";
	}
//---------获取首页商品json数据--------
	var url = "data/data.json";
	ajax.get(url, function(str){
	var obj = eval("("+str+")");
	arr = obj.list;
	var arrthedl = document.getElementsByClassName('goodsdl');
		for(var i=0;i<arr.length;i++){
			var ob = arr[i];
			var obl = arrthedl[i];
			var thedt = document.createElement("dt");
			var thea = document.createElement("a");
			var img = document.createElement("img");
			img.src = ob.src;
			thea.appendChild(img);
			thedt.appendChild(thea);
			thea.href = ob.href;
			var thedd = document.createElement("dd");
			var thep = document.createElement("p");
			thep.innerHTML = ob.p;
			thedd.appendChild(thep);
			var thediv = document.getElementsByClassName("pricecart")[i];
			var thea1 = document.createElement("a");		
			var thesp = document.createElement("span");
			thesp.innerHTML = "￥"+ob.span;
			thea1.appendChild(thesp);	
			thediv.appendChild(thea1);
			thea1.href = ob.href;
			thedd.appendChild(thediv);
			arrthedl[i].appendChild(thedt);
			arrthedl[i].appendChild(thedd);
		}
	});
//------------轮播图------------
	var ul = document.getElementById("carul");
	var ol = document.getElementById("carol");
	var cLi = ul.children;
	var aLi = ol.children;
	var now=0;
	cLi[0].style.opacity = 1;
	for(var i=0;i<aLi.length;i++){
		var li = aLi[i];
		li.index = i;
		li.onclick = function(){
			now = this.index;
				tab();
			}
		}
	function tab(){
		for(var i=0;i<aLi.length;i++){
			var li = aLi[i];
			li.className="";
			startMove(cLi[i], {opacity:0});
		}
		aLi[now].className = "select";
			startMove(cLi[now], {opacity:100});
	}
	//定时器
	function next(){
		now++;
		if(now==aLi.length)now=0;
		tab();
	}
	var timer = setInterval(next,3000);
	var box = document.getElementById("box");
	box.onmouseover = function(){
		clearInterval(timer);
	}
	box.onmouseout = function(){
		timer = setInterval(next,3000);
	}
//-----------购物车-----------
	var shopping = document.getElementsByClassName("shopping")[0];
	var cargoods = document.getElementsByClassName("cargoods")[0];
	var balance = document.getElementsByClassName("balance")[0];
	var timer1 = null;
	var isin = false;
	shopping.onmouseover = function(){
		cargoods.style.display = "block";
		clearTimeout(timer1);
	}
	shopping.onmouseout = function(){
		clearTimeout(timer1);
		timer1 = setTimeout(function(){
			if(!isin){
				cargoods.style.display = "none";
			}
		},1000);
	}
	cargoods.onmouseover = function(){
		isin = true;
	}
	cargoods.onmouseout = function(){
		isin = false;
		this.style.display = "none";
	}
	balance.onclick = function(){
		window.location="cart.html";
	}




//---------------------
	/*var lt = document.getElementsByClassName("lt")[0];
	var gt = document.getElementsByClassName("gt")[0];
	var carpics = document.getElementsByClassName("carpic");
	var ltgt = document.getElementById("ltgt");
	var notice = document.getElementById("notice");
	ltgt.onmouseover = function(){
			lt.style.display = "block";
			gt.style.display = "block";
		}
		ol.onmouseover = function(){
			lt.style.display = "block";
			gt.style.display = "block";
		}
		notice.onmouseover = function(){
			lt.style.display = "block";
			gt.style.display = "block";
		}
	for(var i=0;i<carpics.length;i++){
		carpics[i].index = i;
		carpics[i].onmouseover = function(){
			lt.style.display = "block";
			gt.style.display = "block";
		}

		carpics[i].onmouseout = function(){
			lt.style.display = "none";
			gt.style.display = "none";
		}
	}

	lt.onmouseover = function(){
					clearInterval(timer);
				}

		/*function tab1(){
			for(var i=0;i<aLi.length;i++){
			var li = aLi[now];
			li.className="";
			startMove(cLi[i], {opacity:0});
		}
			aLi[now-1].className = "select";
			startMove(cLi[now-1], {opacity:100});
		}

	/*lt.onclick = function(){
		tab1();
now--;

	}
	//
				function next1(){
					clearInterval(timer);
			
					now++;
					if(now==aLi.length)now=0;
					tab();
				}
				
				var timer = setInterval(next1,3000);
				var box = document.getElementById("box");
				box.onmouseover = function(){
					clearInterval(timer);
				}

				box.onmouseout = function(){
					timer = setInterval(next1,3000);
				}*/
//---------登陆成功后用户名的修改-----------
	var welcome = document.getElementsByClassName("welcome")[0]; 
	var welto = document.getElementsByClassName("welto")[0];
	var safel = document.getElementsByClassName("safel")[0];
	var tojoin = document.getElementsByClassName("tojoin")[0];
	var fre = document.getElementsByClassName("fre")[0];
	var userlogin=getCookie("userlogin");
	if(userlogin!=""){
		welto.innerHTML = "亲爱的";
		safel.innerHTML = userlogin;
		tojoin.innerHTML = "您好";
		fre.innerHTML = "";
		var a = document.createElement("a");
		welcome.appendChild(a);
		a.innerHTML = "[退出]";
		a.onclick = function(){
			setCookie("userlogin", "", -10);
				history.go(0);
		}
	}
//--------搜索框-----------
/*var txt = document.getElementsByClassName("txt")[0];
var btn = document.getElementsByClassName("btn")[0];
var txtxl = document.getElementsByClassName("txtxl")[0];
var list= txtxl.children;
txt.onfocus=function(e){
	txt.onclick = function(e){
	var evt = e || event;
	txtxl.style.display = "block";
		for(var i in list){
		list[i].index = i;
		list[i].onclick = function(){
		txt.value = list[this.index].innerText;
		txtxl.style.display = "none";
		}
	}
}*/
//------------购物车数量------------
var goodsnumb = document.getElementById("goodsnumb");
var cargoods = document.getElementsByClassName("cargoods")[0];
if(getCookie("length")!=""){
	goodsnumb.innerHTML = getCookie("length");
	cargoods.innerHTML = "您的购物车里有"+getCookie("length")+"件商品";
}else{
	goodsnumb.innerHTML = 0;
	cargoods.innerHTML = "您的购物车里还没有商品哦";
}
//----------搜索框-------------
var arr1;
var url="data/word.json?t="+new Date().getTime();//数据
ajax.post(url,"x=2", function(str){//ajax
	arr1=eval("("+str+")").list;//得到数组
});	
var ttxt = document.getElementsByClassName("txt")[0];
ttxt.onkeyup = function (){
	var word=document.getElementsByClassName("txt")[0].value;//得到文本域中的值
	var div1=document.getElementById("div1");//得到提示菜单div
	div1.innerHTML="";//提示菜单清空内容。如果不做清空，数据将累加。
	if(word!=""){//当文本域中的值为空时
		var reg=eval("/"+word+"/gi");//声明正则
		for(var i=0; i<arr1.length; i++){//遍历
			var obj=arr1[i];//得到对象	
	var txt=obj.key;	//指 列表中具体的一项
	
	var col=txt.match(reg);	//根据正则取出匹配的结果
	if(col){
		t2=txt;
		a2=txt.split(reg);
		s2="";
		for(var j=0; j<col.length; j++){
			s2 += a2[j]+"<font color=red>"+col[j]+"</font>"	
			//col[j].style.margin = "5px 0 0 5px";				
		}		
		s2+=a2[j];
		txt="<div onclick=\"Change('"+obj.key+"')\">"+s2+"</div>";//绑定单击事件				
		div1.innerHTML+=txt;
			}
		}	
		if(div1.innerHTML!=""){
			div1.style.display="block";
		}		
	}else{
		div1.style.display="none";
	}
}
var btn = document.getElementsByClassName("btn")[0];
btn.onclick = function(){
	var word=document.getElementsByClassName("txt")[0].value;//得到文本域中的值
	if(word=="服装鞋帽"||word=="寒豹男士服装"||word=="Z-X时尚印花服装"||word=="COOREENA女士服装"){
		document.documentElement.scrollTop = document.body.scrollTop = 1100;
	}
	if(word=="家用电器"||word=="苏泊尔CYSB50YC10D-100"||word=="苏泊尔 SDHCB8E30-210"){
		document.documentElement.scrollTop = document.body.scrollTop = 1760;
	}
	if(word=="家居生活"||word=="全棉夏被"||word=="纯天然冰丝夏被"){
		document.documentElement.scrollTop = document.body.scrollTop = 2420;
	}
	if(word=="母婴玩具"||word=="玩具麦迪熊"||word=="玩具海浪投影故事机"){
		document.documentElement.scrollTop = document.body.scrollTop = 3080;
	}
	if(word=="运动户外"||word=="喵咖 M6 户外磁吸附运动音乐蓝牙耳机"||word=="山夫 QF-02 蓝牙音响背包运动户外旅游双肩包"){
		document.documentElement.scrollTop = document.body.scrollTop = 3740;
	}
	if(word=="个护美妆"||word=="伊诗兰顿绿豆泥浆面膜"||word=="男士海洋弛爽补水蚕丝面膜"){
		document.documentElement.scrollTop = document.body.scrollTop = 4400;
	}
	if(word=="食品保健"||word=="休闲食品"||word=="麦轩食品蛋黄白莲蓉月饼"){
		document.documentElement.scrollTop = document.body.scrollTop = 5060;
	}
}
//---------回到顶部---------
 var gotop = document.getElementById("gotop");
 gotop.onclick = function(){
 	document.documentElement.scrollTop = document.body.scrollTop = 0;
 }
//-----------楼梯---------------
function getScrollTop(){
var scrollTop=0;
if(document.documentElement&&document.documentElement.scrollTop){
scrollTop=document.documentElement.scrollTop;
}else if(document.body){
scrollTop=document.body.scrollTop;
}
return scrollTop;
} 
var arrfloor = [1100,1760,2420,3080,3740,4400,5060];
var l = 7;
arrfloor.push(arrfloor[arrfloor.length-1]+4400);
var h=parseInt(document.documentElement.clientHeight/2);
window.onscroll = function(){
	var s = getScrollTop() ;
	var index;
	for(var i=arrfloor.length-1; i>=0; i-- ){			
			if(s>=(arrfloor[i]-330) ){
				index=i;
				break;
			}
			else{
				index=0
			}
		}
		var flsp = document.getElementsByClassName("flsp");
		for(var i=0;i<flsp.length;i++){
			flsp[i].style.background = "white";
			flsp[index].style.background = "#666";
		}
}

//var tfloor = document.getElementById("floor");
//var arrf = floor.children;
//arrf[0].onclick = function{
//	document.documentElement.scrollTop = document.body.scrollTop = 1100;
//}




}